import 'package:flutter/material.dart';

class MyTab extends StatefulWidget {
  const MyTab({super.key});

  @override
  _MyTabState createState() => _MyTabState();
}

class _MyTabState extends State<MyTab> {
  static List tabsObj = [
    {'name': '点菜', 'num': 0, 'showtital': true},
    {'name': '评价', 'num': 1796, 'showtital': false},
    {'name': '商家', 'num': 0, 'showtital': false}
  ];

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Expanded(
            child: Row(children: [
          Expanded(
              child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: tabsObj.map((item) {
              return Column(
                children: [
                  Row(
                    children: [
                      Text(
                        item['name'].toString(),
                        style: const TextStyle(
                            fontSize: 16, fontWeight: FontWeight.bold),
                      ),
                      item['num'] > 0
                          ? Text(
                              item['num'].toString(),
                              style: const TextStyle(
                                  fontSize: 12, color: Colors.grey),
                            )
                          : const SizedBox(width: 0, height: 0)
                    ],
                  ),
                  item['showtital']
                      ? Container(
                          width: 20,
                          height: 1,
                          margin: const EdgeInsets.only(top: 5),
                          decoration: BoxDecoration(
                            color: Colors.orange,
                            borderRadius: BorderRadius.circular(1),
                          ),
                          child: null,
                        )
                      : Container(
                          width: 20,
                          height: 1,
                          margin: const EdgeInsets.only(top: 5),
                          decoration: BoxDecoration(
                            color: Colors.transparent,
                            borderRadius: BorderRadius.circular(1),
                          ),
                          child: null,
                        )
                ],
              );
            }).toList(),
          )),
          _seach(),
        ]))
      ],
    );
  }

  Widget _seach() {
    return Container(
      margin: const EdgeInsets.only(left: 10),
      padding: const EdgeInsets.only(left: 10),
      width: 170,
      height: 30,
      decoration: BoxDecoration(
        color: Colors.grey[200],
        borderRadius: BorderRadius.circular(15),
      ),
      child: const Row(
        children: [
          Icon(
            Icons.search,
            size: 20,
            color: Colors.grey,
          ),
          Text(
            '搜索',
            style: TextStyle(
                fontSize: 16, fontWeight: FontWeight.bold, color: Colors.grey),
          ),
        ],
      ),
    );
  }
}
